import 'package:flutter/material.dart';

class AnimationSuoFangWidget extends StatefulWidget {
  const AnimationSuoFangWidget({super.key});

  @override
  State<AnimationSuoFangWidget> createState() => _AnimationSuoFangWidgetState();
}

class _AnimationSuoFangWidgetState extends State<AnimationSuoFangWidget>
    with SingleTickerProviderStateMixin {
  late AnimationController _animationController;
  late Animation<double> _animation;
  @override
  void initState() {
    _animationController = AnimationController(
      vsync: this,
      duration: const Duration(seconds: 2),
    );
    _animation = Tween<double>(
      begin: 1.0,
      end: .5,
    ).animate(_animationController);

    _animationController.repeat();
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.amber,
        title: const Text('案例-动画-缩放'),
      ),
      body: Center(
        child: GridView(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            mainAxisSpacing: 10,
            crossAxisSpacing: 5,
          ),
          children: List.generate(4, (index) {
            return ScaleTransition(
              scale: _animation,
              child: Container(width: 100, height: 100, color: Colors.green),
            );
          }),
        ),
      ),
    );
  }
}
